#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#include<stdlib.h>
#include<malloc.h>
#define MAX_PATH_SIZE 100
#define MAXBUCKETS 27
#define MAX_DIR 20



typedef struct FileDescriptor {
	char file_name[50];
	char path[50];
	char fileType;
	int fileSize;
	int blockNum;
}fd;

long int nBlocks;
long int fdcounter;
int ismounted;
long int offset;

struct MainHeader {
	
	char fileSystemLabel[50];
	int maxNoOfFileDescriptor;
	int noOfUsedFileDescriptor;

} header;




typedef struct freelist{
	char value;
}flist;


typedef struct nrytree_node
{
	fd *data;
	int is_deleted;
	struct nrytree_node *left_child; 
	struct nrytree_node *right_siblings; 
	struct nrytree_node *parent; 
}t_node;

t_node	*naryRoot;





struct HashTable
{
	struct LinkedListNode *buckets[MAXBUCKETS] ;
};

struct LinkedListNode
{
        //char *key;
        fd* fileDesc;
        struct LinkedListNode *next;
};

struct HashTable *hash;



//BST
struct Index
{
	char *key; //path+filename of file
	fd *data;
	
	
};

struct bstNode
{
struct Index *data; 
struct bstNode *rightChild;
struct bstNode *leftChild;
};

struct bstNode *bstRoot;
fd * bstSearchNode(struct bstNode **rootNode,char *fullpath);
char* fetchFileName(char* fileFullPath) ;

//VFS
//void create_Vfs(char *vfs_label, int size);
int mountVfs(char *vfs_label);

int unmount_vfs(char *vfs_label);

//int write_desc(t_node *root, char *filename,int count);
//int write_desc(t_node *root,fd fdarray[],int j);
int write_desc(t_node *root, char *filename,int count);


int create_dir(char *path, char *dirname);

int move_dir(t_node** root,char *source,char *dest);
char* extrctslash(char* s);
void modify_fd(t_node** root,t_node *t,char *source,char *dest); 
//int listdir(t_node** root,char*dir_name,char flag, char*outputfile);
int list_dir(t_node** root,char*dir_name,int flag, char*outputfile);
int write_to_file_recursive(t_node *root,char *outputfile);
int write_to_file(t_node *root,char*outputfile);
int delete_nodes(t_node** root, char *fullpath);
void searchfile( char *P1, char *P2 );

void add_file(char *dirName, char *fileName, char *filePath);
void list_file(char *filePath, char *outputfile);
int export_file(char *filePath, char *outputfile);
int update_file ( char filePath[],char *sourceFilePath );
void remove_file(char *fpath);
void move_file(char *source_file_path,char *dest_file_path) ;
//void write_desc(int update_file ( char filePath[],char *sourceFilePath )t_node *root, struct FileDescriptor writearray1[]);

//Utility function definition
int checkNameValidity(char* fileName);
char* parsePath(char *path);
int lastcharcheck(char *path);


//test function

void testfunc();
